<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<meta charset="UTF-8">
	<title>修改新闻信息</title>
	<meta name="renderer" content="webkit">	
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">	
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">	
	<meta name="apple-mobile-web-app-status-bar-style" content="black">	
	<meta name="apple-mobile-web-app-capable" content="yes">	
	<meta name="format-detection" content="telephone=no">	
	<link rel="stylesheet" type="text/css" href="common/layui/css/layui.css" media="all">
	<link rel="stylesheet" type="text/css" href="common/bootstrap/css/bootstrap.css" media="all">
	<link rel="stylesheet" type="text/css" href="common/global.css" media="all">
	<link rel="stylesheet" type="text/css" href="css/personal.css" media="all">
	<script type="text/javascript" src="js/jquery-1.7.2.min.js"></script>
	<script  src="common/timelayui/laydate/laydate.js"></script>
</head>
<body class="childrenBody">
	<form class="layui-form">
		<div class="layui-form-item">
		<!-- 用一个隐藏的文本域来存Id-->
		<input type="hidden" name='cid' value='${param.id}'>
			<label class="layui-form-label">新闻标题</label>
			<div class="layui-input-block">
				<input  name="centerName" class="layui-input newsName" lay-verify="required" placeholder="请输入新闻标题" type="text">
			</div>
		</div>
		<div class="layui-form-item">
			<div class="layui-inline">		
				<label class="layui-form-label">新闻类型</label>
				<div class="layui-input-block">
					<select id="selSex"  class="newsLook" lay-filter="browseLook">
				        
				    </select>
				</div>	
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">新闻类容</label>
			<div class="layui-input-block">
				<textarea name="centerText" class="layui-input newsName" lay-verify="required" placeholder="请输入新闻类容"></textarea>
			</div>
		</div>
		<div class="layui-form-item">
			<div class="layui-inline">		
				<label class="layui-form-label">发布日期</label>
				<div class="layui-input-inline">
					<input type='text' name='centerTime' class='layui-input datetime newsTime' lay-verify="required|date">
				</div>
			</div>
		</div>
		<div class="layui-form-item">
			<div class="layui-input-block">
				<span class="layui-btn"  name="qrxg"  lay-filter="addNews">确认修改</span>
				<span name="qxxg" class="layui-btn layui-btn-primary">取消修改</span>
		    </div>
		</div>
	</form>
	<script type="text/javascript" src="common/layui/layui.js"></script>
	<script>
	layui.use(['form','element','jquery','layer','laydate'], function(){
		var $=layui.jquery,form=layui.form,laydate = layui.laydate;
		$(function(){
			//核心方法 
			function timeAdd(){ 
				lay('.datetime').each(function() { 
				laydate.render({ elem : this, trigger : 'click'}); 
				});
			}
			//转换时间格式的方法
			function showDate(longTypeDate){
				if(longTypeDate==undefined){
					return "未设置";
				}
				var dateType = ""; 
				var date = new Date(); 
				date.setTime(longTypeDate); 
				dateType += date.getFullYear();  //年 
				dateType += "-" + getMonth(date); //月  
				dateType += "-" + getDay(date);  //日 
				return dateType;
			} 
			//返回 01-12 的月份值  
			function getMonth(date){ 
				var month = ""; 
				month = date.getMonth() + 1; //getMonth()得到的月份是0-11 
				if(month<10){ 
					month = "0" + month; 
				} 
				return month; 
			} 
			//返回01-30的日期 
			function getDay(date){ 
				var day = ""; 
				day = date.getDate(); 
				if(day<10){ 
					day = "0" + day; 
				} 
			
				return day; 
			}
			
			show_upadate();
			$("span[name='qxxg']").bind('click',function(){
				
				show_upadate();
			})
			function show_upadate(){
				
				var cid=$("input[name='cid']").val();
				$("#selSex").text("");
				$("input[name=centerName]").val("");
				$("textarea[name='centerText']").val("");
				$(".newsTime").val("");
				//加载职位下拉ajax
				$.ajax({
				type:"POST",
				dataType:"json",
				url:"../informationAction!selectType",
				async:false,
				success:function(msg){
						$(msg).each(function(index){
							$("#selSex").append("<option name='centerType' value='"+msg[index].itiid+"'>"+msg[index].ititype+"</option>");
							form.render('select');
						});
						
					}
				});
				
				$.ajax({
					type:"POST",
					dataType:"json",
					data:{"cid":cid},
					url:"../informationAction!show_Center",
					success:function(msg){
						$("input[name=centerName]").val(msg.icititle);
						$("#selSex").find("option[value='"+msg.infotypeinfo.itiid+"']").prop("selected",true);
						$("textarea[name='centerText']").val(msg.icicontext);
						$(".newsTime").val(showDate(msg.icitime));
						form.render('select');
					}
				});
				form.render(); 
		        timeAdd();
			}
			
			
		});
	});
	
	//修改新闻的方法
	$("span[name=qrxg]").bind('click',function(){
		var cid=$("input[name='cid']").val();
	 	var centerName=$("input[name=centerName]").val();
	 	var centerType=$("option[name=centerType]:checked").val();
	 	var centerText=$("textarea[name=centerText]").val();
	 	var centerTime=$("input[name='centerTime']").val();
	 	$.ajax({
			type:"POST",
			dataType:"json",
			data:{"cid":cid,"centerName":centerName,"centerType":centerType,"centerText":centerText,"centerTime":centerTime},
			url:"../informationAction!updateCenter",
			success:function(msg){
				layer.alert('数据修改成功！！！', {icon: 1});
			}
					
	 	});
	})
	
	
	

	
	</script>
</body>
</html>